<template>
  <div>
    <a
      v-if="repo && fkey"
      :href="getDownloadUrlExtended(endpoint, id, filename, repo, fkey)"
      >{{ filename }}</a
    >
    <a v-else :href="getDownloadUrl(endpoint, id, filename)">{{ filename }}</a>
  </div>
</template>

<script>
export default {
  name: "FileDownload",
  props: ["endpoint", "filename", "fkey", "id", "repo"],
  methods: {
    getDownloadUrlExtended: function(url, id, filename, repo, fkey) {
      return `${url}?id=${id}&filename=${filename}&repo=${repo}&fkey=${fkey}`;
    },
    getDownloadUrl: function(url, id, filename) {
      return `${url}?id=${id}&filename=${filename}`;
    }
  }
};
</script>
